//
//  ZZNetWorkBaseResponse.m
//  ZZNetWorker
//
//  Created by ZengLiZhi on 2024/1/31.
//

#import "ZZNetWorkResponse.h"
#import "MJExtension/MJExtension.h"
#import "ZZNetWorkRequest.h"
#import <SVProgressHUD/SVProgressHUD.h>

@implementation ZZNetWorkResponse

- (ZZNetWorkResponse *)setKeyValues:(NSDictionary *)json{
    [self mj_setKeyValues:json];
    self.originalData = json;
    return self;
}


- (BOOL)success{
    if (!_success) {
        return self.code == 200;
    }
    return _success;
}

//数据转模型
- (void)setData:(id)data{
    
    _data = data;
    if ([data isKindOfClass:[NSArray class]]) {
        self.objArray = [[self.dataClass class] mj_objectArrayWithKeyValuesArray:data];
    }else if([data isKindOfClass:[NSDictionary class]]){
        self.obj = [[self.dataClass class] mj_objectWithKeyValues:data];//T
    }else if([data isKindOfClass:[NSString class]]){
        self.obj = data;
    }else{
        self.obj = data;
    }
    
}

- (BOOL)codeVerify:(ZZNetWorkRequest *)request{
    
    if (self.success) {
        return YES;
    }
    
    //弹窗提示错误信息
    if (request.isShowErrorMessage) {
        [self showMessage:self.msg];
    }
    
    return YES;
}

- (void)showMessage:(NSString *)message{
    [SVProgressHUD dismiss];
    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:message];
}
@end
